<template>
  <!-- tab基本信息表单  -->
  <el-scrollbar style="height: 100%;margin-top:10px;">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="90px"
      class="form-input-m"
      inline-message
    >

      <el-form-item label="型号" prop="specboxModel">
        <el-input v-model="formData.specboxModel" placeholder="请输入型号" clearable></el-input>
      </el-form-item>
<!--      <el-form-item label="适用试管范围" prop="tubeTypesRange">-->
<!--        <el-input v-model="formData.tubeTypesRange" placeholder="请输入适用试管范围" clearable></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="适用温度" prop="tempRange">
        <el-input v-model="formData.tempRange" placeholder="请输入适用温度" clearable></el-input>
      </el-form-item>
      <el-form-item label="阵列" prop="specboxArray">
        <el-input v-model="formData.specboxArray" placeholder="请输入阵列" clearable></el-input>
      </el-form-item>
      <el-form-item label="仓位序列" prop="orderNumber">
        <el-input v-model="formData.orderNumber" placeholder="请输入仓位序列"
                  type="textarea"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="尺寸" prop="specboxSize">
        <el-input v-model="formData.specboxSize" placeholder="请输入尺寸" clearable></el-input>
      </el-form-item>
      <el-form-item label="用途" prop="purpose">
        <el-input v-model="formData.purpose" placeholder="请输入用途"
                  type="textarea"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="" prop="">
        <el-button type="primary" @click="saveForm">保存</el-button>
      </el-form-item>
    </el-form>
  </el-scrollbar>
</template>

<script lang="ts" setup>
// 引入组件区 ==========
import {
  ref,
  reactive,
  watch,
  getCurrentInstance,
  PropType,
  onMounted
} from 'vue';
import { IsEmpty, formatDateTime } from '@/utils/common'; //导入工具函数
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { funBdsJsResult } from '@/utils/Expression'; //函数公式
import SelectDataGrid from '@/components/SelectDataGrid.vue';
import { AppStore } from '@/stores/store';
import {  FormInstance } from 'element-plus';
import {
samstoSpecboxModelAdd,
samstoSpecboxModelEdit
} from '@/views/lab_sys/samsto_set/apis/samsto_api';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let store = AppStore();
let orgId = ref(null);
const formRef = ref<FormInstance>; //表单ref标记
// 表单绑定的数据类型限制
interface FormDataVO {
            id: string /*主键*/;
  	  			specboxModel: String ;/*型号 */
	    	  			tubeTypesRange: String ;/*适用试管范围 */
	    	  			tempRange: String ;/*适用温度 */
	    	  			specboxArray: String ;/*阵列 */
	    	  			orderNumber: String ;/*仓位序列 */
	    	  			specboxSize: String ;/*尺寸 */
	    	  			purpose: String ;/*用途 */
	    	  			status: Number ;/*状态 */
		  	  			deptName: String ;/*所属科室 */
	    }
// 表单绑定的数据
let formData = reactive<FormDataVO>({
            id: '',
      			specboxModel: '' ,/*型号 */
	      			tubeTypesRange: '' ,/*适用试管范围 */
	      			tempRange: '' ,/*适用温度 */
	      			specboxArray: '' ,/*阵列 */
	      			orderNumber: '' ,/*仓位序列 */
	      			specboxSize: '' ,/*尺寸 */
	      			purpose: '' ,/*用途 */
	      			status: 1 ,/*状态 */
		      			deptName: '' ,/*所属科室 */
	  });
let types = reactive([]);
// 表单校验规则
const formRules: any = {
  specboxModel:[{ required: true, message: '请输入型号' }],
  tempRange:[{ required: true, message: '请输入适用温度' }],
  specboxArray:[{ required: true, message: '请输入阵列' }],
  orderNumber:[{ required: true, message: '请输入仓位序列' }],
};

defineExpose({
  addNew,
  saveForm
});

// 父组件传值
let props = defineProps({
  currentRow: { type: Object as PropType<any>, required: true }
}) as any;
watch(
  () => props.currentRow,
  (nval, oval) => {
    Object.assign(formData, nval);
  },
  {
    deep: true,
    immediate: true
  }
);


onMounted(() => {
  orgId = store.userInfo.orgId;
  //formData.bankNumber=generateCode();
});


// 方法定义区 =============
//生成题库编码
function generateCode() {
  let now = new Date();
  console.log(now,"now");
  let y = now.getFullYear(),
    m = now.getMonth() + 1,
    d = now.getDate(),
    h = now.getHours(),
    mm = now.getMinutes(),
    s = now.getSeconds(),
    ms = now.getMilliseconds();
  return "TM"+y + m+d+h+mm+s+ms;
}
function addNew(callback: any) {
  clear();
  if (callback) {
    callback({ a: '初始化完成' });
  }
}
// 清空表单
function clear() {
  //formData.startus = 1;
  //formData.bankNumber = generateCode();
  //formData.seq = 1;
  formData.id = "";
    			formData.specboxModel= '' ;/*型号 */
	    			formData.tubeTypesRange= '' ;/*适用试管范围 */
	    			formData.tempRange= '' ;/*适用温度 */
	    			formData.specboxArray= '' ;/*阵列 */
	    			formData.orderNumber= '' ;/*仓位序列 */
	    			formData.specboxSize= '' ;/*尺寸 */
	    			formData.purpose= '' ;/*用途 */
	    			formData.status= 1 ;/*状态 */
		    			formData.deptName= '' ;/*所属科室 */
	}

// 保存信息
function saveForm() {
  submitForm();
}

// 保存
const submitForm = () => {
  let elInfo = proxy.$refs.formRef;
  elInfo.validate(async (valid: any) => {
    if (!valid) {
      return false;
    }
    let res: any;
    if (IsEmpty(formData.id)) {
      res = await samstoSpecboxModelAdd(formData);
    } else {
      res = await samstoSpecboxModelEdit(formData);
    }
    res.status.code === 1 ? VxeMessage(res.status.msg, VxeNotifyType.success) : VxeMessage(res.status.msg, VxeNotifyType.error);
    clear();
    proxy.$emit('findList');
  });
};
function selectRow(e, rowIndex) {
  if (!IsEmpty(e)) {
    formData.deptName = e.code;
  }
};
const states = [
  {
    value: 1,
    label: '启用'
  },
  {
    value: 0,
    label: '停用'
  }
];
</script>

<style lang="scss" scoped>
// 中等尺寸时 配置扩展属性按钮
.el-button--default {
  padding: 5px 11px;
}
</style>

